package org.aplombh.java.utils;

public class SwapUtils {

    /**
     * 交换数组中两数的值 Swap the values of two numbers in array
     *
     * @param i    数组下标 array index
     * @param j    数组下标 array index
     * @param ints 数组 array
     */
    public static void swap(int i, int j, int[] ints) {
        int t = ints[i];
        ints[i] = ints[j];
        ints[j] = t;
    }

    /**
     * 交换字符串中两字符位置 Swap the position of two chars in String
     *
     * @param i   下标 array index
     * @param j   下标 array index
     * @param str 数组 array
     */
    public static String swap(int i, int j, String str) {
        StringBuilder sb = new StringBuilder(str);
        char temp = sb.charAt(i);
        sb.setCharAt(i, sb.charAt(j));
        sb.setCharAt(j, temp);
        return sb.toString();
    }
}
